Skip to content

fix: keep milliseconds in datetime start and end bounds - #752

Open
pcbeingused333 wants to merge 1 commit into
ably:mainfrom
pcbeingused333:fix/time-param-milliseconds
Open

pcbeingused333 wants to merge 1 commit into
ably:mainfrom
pcbeingused333:fix/time-param-milliseconds

Conversation

@pcbeingused333

@pcbeingused333 pcbeingused333 commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

A datetime passed as start or end to channel history() or stats() is truncated to whole seconds. For example, 12:00:00.999 is sent as ...12:00:00.000, so a window ending there leaves out up to 999 ms of results.

The cause is that format_time_param computes calendar.timegm(t.utctimetuple()) * 1000, and a time tuple has no sub-second field. The fix adds t.microsecond // 1000. This matches what presence history() already sends (_ms_since_epoch in ably/pubsub/types/presence.py). Naive datetimes are still read as UTC, and non-datetime values are passed through as before.

A parametrized test in test/unit/paginatedresult_test.py covers UTC, offset-aware and naive datetimes. It fails without the change and passes with it. The paginated result, stats and channel unit tests pass, and ruff is clean.

This change was prepared with the help of an AI coding assistant.

Summary by CodeRabbit

  • Bug Fixes
    • Paginated result queries now preserve timestamp precision to the millisecond, preventing records near a requested start or end time from being missed due to discarded fractional seconds.
    • Datetime bounds now produce consistent millisecond query parameters for UTC, offset-aware, and naive values.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Datetime query bounds now retain millisecond precision. Tests cover UTC-aware, offset-aware, and naive datetime values for both start and end.

Changes

Datetime bound precision

Layer / File(s) Summary
Format datetime bounds
ably/pubsub/request/paginatedresult.py, test/unit/paginatedresult_test.py
format_time_param adds the datetime’s microseconds, truncated to milliseconds. Parameterized tests verify that all three datetime forms produce 1704110400999 for both bounds.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Possibly related PRs

Suggested reviewers: owenpearson

Merge Risk: Minimal · up to d6ccb

Datetime start and end bounds now keep millisecond precision in channel history and stats queries. The change is small, covered by tests, and easy to revert, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: datetime start and end bounds now keep milliseconds. The raw summary says format_time_param now includes microseconds truncated to milliseconds, and the objectives des…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: datetime start and end bounds now keep milliseconds. The raw summary says format_time_param now includes microseconds truncated to milliseconds, and the objectives describe adding t.microsecond // 1000 to the timestamp calculation. The title is specific, concise, and matches the changeset.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks the clock’s fine hand,
Milliseconds now join the band.
UTC, offset, and plain time agree,
Start and end keep precision neatly.
The bounds hop on, no second lost.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 14a5f22d-ada2-4f1a-b38b-fdeacdce412f
Commits

Reviewing files that changed from the base of the PR and between 2435510 and d6ccb5d.

Files selected for processing: 2

  • ably/pubsub/request/paginatedresult.py
  • test/unit/paginatedresult_test.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant